import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import javax.xml.transform.Result;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-07-07
 * Time: 23:19
 */
public class TEst2 {
    public static void main(String[] args) throws SQLException {
        MysqlDataSource dataSource = new MysqlDataSource();
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/java112?characterEncoding=utf8&useSSL=false");
        dataSource.setUser("root");
        dataSource.setPassword("071711");

        Connection connection = dataSource.getConnection();

        //System.out.println(connection);

        String sql = "select * from student2";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        ResultSet resultSet = preparedStatement.executeQuery();

        while(resultSet.next()) {
            System.out.print( resultSet.getInt("id"));
            System.out.print(" ");
            System.out.println( resultSet.getString("name"));
        }

        resultSet.close();
        preparedStatement.close();
        connection.close();

    }
}
